package com.wwj.core.server.service.impl;

import com.wwj.core.server.entity.NotifyServer;
import com.wwj.core.server.entity.mapper.NotifyServerMapper;
import com.wwj.core.server.service.INotifyServerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NotifyServerServiceImpl implements INotifyServerService{
    @Resource
    private NotifyServerMapper notifyServerMapper;

    @Override
    public NotifyServer findByServerName(String serverName) throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("serverName", serverName);
        List<NotifyServer> list = notifyServerMapper.selectByParam(param);
        return list != null && list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public int createNewServer(NotifyServer server) throws Exception {
        server.setCreateTime(Calendar.getInstance().getTime());
        return notifyServerMapper.save(server);
    }

    @Override
    public int updateServer(NotifyServer server) throws Exception {
        server.setUpdateTime(Calendar.getInstance().getTime());
        return notifyServerMapper.update(server);
    }
}
